選択範囲をnote (Anki)にするPopupMenu@0.1.0
code:${guid}.noteを作るpopup menuを作る
code:popup.ts
import { makeNoteGUID } from "../deno-anki/mod.ts";
import { getIndentCount } from "../scrapbox-userscript-std/text.ts";
import { Scrapbox } from "../scrapbox-jp%2Ftypes/userscript.ts";
declare const scrapbox: Scrapbox;
scrapbox.PopupMenu.addButton({
title: "make note",
onClick: (text) => {
const body = text.split("\n").map((line) => ${line});
const minIndent = Math.min(
...body.map((line) => getIndentCount(line))
) - 1;
return [
${" ".repeat(minIndent)}code:${makeNoteGUID()}.note,
...body,
].join("\n");
},
});
code:popup2.ts
import { makeNoteGUID } from "../deno-anki/mod.ts";
import { getIndentCount } from "../scrapbox-userscript-std/text.ts";
import { Scrapbox } from "../scrapbox-jp%2Ftypes/userscript.ts";
declare const scrapbox: Scrapbox;
scrapbox.PopupMenu.addButton({
title: "make note",
onClick: (text) => {
const body = text.split("\n").map((line) => ${line});
const minIndent = Math.min(
...body.map((line) => getIndentCount(line))
) - 1;
const title = ${" ".repeat(minIndent)}code:${makeNoteGUID()}.note;
return [
title,
...body,
${title}.Description,
${title}.Sound(txt),
].join("\n");
},
});
code:popup.js
var s="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!#$%&()*+,-./:;<=>?@[]^_{|}~",a=()=>{let e=Math.floor(Math.random()*Number.MAX_SAFE_INTEGER),t="";for(;e>0;){let r=Math.floor(e/s.length),n=e%s.length;t+=s[n],e=r}return t.split("").reverse().join("")};var i=e=>e.match(/^(\s*)/)?.[1]?.length??0;scrapbox.PopupMenu.addButton({title:"make note",onClick:e=>{let t=e.split(
).map(o=> ${o}),r=Math.min(...t.map(o=>i(o)))-1,n=${" ".repeat(r)}code:${a()}.note;return[n,...t,${n}.Description,${n}.Sound(txt)].join(
`)}});